package com.lanhao.aot.ip2region;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.lionsoul.ip2region.DataBlock;
import org.lionsoul.ip2region.DbConfig;
import org.lionsoul.ip2region.DbMakerConfigException;
import org.lionsoul.ip2region.DbSearcher;

import cn.hutool.core.io.IoUtil;


public class LionIp2Region {
	public static void main(String[] args) throws IOException, DbMakerConfigException {
//		URL url = ResourceUtils.getURL("classpath:ip2region.db");
		URL url = new URL("https://res-oss.anhelogistics.com/file/ip2region.db");
		String path = url.getPath();
		System.out.println(path);
		InputStream openStream = url.openStream();
		byte[] readBytes = IoUtil.readBytes(openStream);
		DbSearcher dbSearcher = new DbSearcher(new DbConfig(), readBytes);
		DataBlock dataBlock = dbSearcher.memorySearch("36.161.110.86");
		String region = dataBlock.getRegion();
		System.out.println(region);
		System.out.println(dataBlock);
	}
}
